import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei']

# 数据
companies = ['泰豪科技', '华丰股份']
total_assets = [13595994070.72, 24024932199.95]
shareholders_equity = [3481787157.43, 1825041450.91]
total_liabilities = [9228236071.55, 577451640.00]

# 设置柱状图的位置
x = np.arange(len(companies))
width = 0.2

# 创建图表
fig, ax = plt.subplots()

# 绘制柱状图
rects1 = ax.bar(x - width, total_assets, width, label='总资产')
rects2 = ax.bar(x, shareholders_equity, width, label='所有者权益')
rects3 = ax.bar(x + width, total_liabilities, width, label='负债总额')

# 添加文本标签、标题和自定义x轴刻度标签
ax.set_ylabel('金额 (元)')
ax.set_title('资产和负债结构分析')
ax.set_xticks(x)
ax.set_xticklabels(companies)
ax.legend()

# 在柱状图上添加数值标签
def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        ax.annotate('{}'.format(height),
                    xy=(rect.get_x() + rect.get_width() / 2, height),
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom')

autolabel(rects1)
autolabel(rects2)
autolabel(rects3)

# 显示图表
plt.show()